<template>
	<uv-picker title="回退选项" ref="picker" :columns="adminHtList" @close="closeFunc" @confirm="confirmFunc" keyName="label"></uv-picker>
</template>

<script setup>
import { computed, watch, onMounted, getCurrentInstance, ref, defineEmits } from 'vue';
const { proxy: that } = getCurrentInstance();
let props = defineProps({
	show: {
		type: Boolean,
		default: () => {
			return false;
		}
	},
	dataObj: {
		type: Object,
		default: () => {
			return {};
		}
	},
	adminHtList: {
		default: () => {
			return [];
		}
	}
});
const emit = defineEmits(['close', 'onSuccess']);

function closeFunc() {
	emit('close', false);
}

function onSuccessFunc() {
	emit('onSuccess', false);
}

onMounted(() => {});
watch(
	() => props.show,
	(newValue, oldValue) => {
		console.log(newValue, oldValue, '值变化');
		if (props.show) {
			that.$refs.picker.open();
		} else {
			that.$refs.picker.close();
		}
	}
);
let confirmFunc = (e) => {
	console.log(e);
	console.log(props.adminHtList);
	let index = props.adminHtList[0].findIndex((item) => {
		return item.label == e.value[0].label;
	});
	console.log(index);
	console.log(props.adminHtList[0][index], '当前选中退回');
	let node_id_arr = [];
	for (let i = index; i < props.adminHtList[0].length; i++) {
		if (e.value[0].node_id && props.adminHtList[0][i].node_id) {
			node_id_arr.push(props.adminHtList[0][i].node_id);
		}
	}
	console.log(node_id_arr, 'node_id_arr');
	that.$Api
		.projectRollback({
			project_id: props.dataObj.id,
			status: e.value[0].value,
			node_id_arr,
			remark: ''
		})
		.then((res) => {
			console.log(res, '项目回退');
			if (res.code == 200) {
				uni.showToast({
					title: '操作成功',
					icon: 'success'
				});
				onSuccessFunc();
			} else {
				uni.showToast({
					title: res.message,
					icon: 'error'
				});
			}
		})
		.catch((err) => {
			uni.showToast({
				title: err.message,
				icon: 'error'
			});
		});
};
// const statusText = computed(() => {

// });
</script>

<style scoped lang="scss"></style>
